package Entities;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;

@Entity
@NamedQueries({
       @NamedQuery(name= "existeMatricula",query="select count(v) from Vehiculo v where v.matricula = :mat and v.activo = true ")
})
public class Vehiculo implements Serializable {

    private static final long serialVersionUID = 1L;
    //Atributos
    @SequenceGenerator(name = "seq", initialValue = 1, allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq")
    @Id
    private int id;
    @Column(name ="matricula",nullable = false,length = 10,unique = true )
    private String matricula;
    @Column(name ="descripcion",nullable = false,length = 255 )
    private String descripcion;
     @Column(name ="activo",nullable = false )
    private boolean activo;

    //Constructores
    public Vehiculo() {
        super();
        this.activo = true;
    }

    public Vehiculo(String matricula, String descripcion) {
        this.matricula = matricula.toUpperCase();
        this.descripcion = descripcion;
        this.activo = true;
    }

    //Getters and Setters
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getMatricula() {
        return matricula;
    }

    public void setMatricula(String matricula) {
        this.matricula = matricula.toUpperCase();
    }

    public String getDescripcion() {
        return descripcion;
    }

    public void setDescripcion(String descripcion) {
        this.descripcion = descripcion;
    }

    public boolean isActivo() {
        return activo;
    }

    public void setActivo(boolean activo) {
        this.activo = activo;
    }

    //toString
    @Override
    public String toString() {
        return "Entity.Vehiculo[ id=" + id + " ]";
    }
}